package cn.ljy.uem.web.action;


import cn.ljy.authority.model.SysUser;
import cn.ljy.authority.service.SysUserService;
import cn.ljy.common.model.result.ResponseData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

//@Api(tags = "后台测试模块")
//@Validated //加了后@NoNull之类的注解才能生效，如果只是@valid注解则不需要加上
//@RestController
//@RequestMapping(value = "/api/test")
public class HelloController {
    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "hello")
    @GetMapping("/testHello")
    @PreAuthorize("hasAuthority('sys:aa')")
    public ResponseData hello(){
        return ResponseData.success(null);
    }

    @ApiOperation(value = "get传递参数测试", notes = "包括参数验证")
    @GetMapping("/testGet")
    @PreAuthorize("hasAuthority('sys:user')")
    public ResponseData hello(Integer number1,@NotNull(message = "账户名不能为空")  String username, @NotEmpty(message = "密码不能为空") String password){
        List<String> list=new ArrayList();
        list.add("zhangsan");
        list.add("xiaohong");
        boolean judge= sysUserService.login(username,password);
        return ResponseData.success(String.valueOf(judge));
    }


    @ApiOperation(value = "post测试", notes = "包括参数验证，json转换")
    @PostMapping("/testPost")
    @PreAuthorize("hasAuthority('test:post')")
    public ResponseData jsonTest(@Valid @RequestBody SysUser sysUser){
        return ResponseData.success(String.valueOf(sysUser));
    }

}
